package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.LuntaiEquipmentUseLog;
import com.ruoyi.system.mapper.LuntaiEquipmentUseLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.LuntaiEquipmentMapper;
import com.ruoyi.system.domain.LuntaiEquipment;
import com.ruoyi.system.service.ILuntaiEquipmentService;

/**
 * 轮胎器材Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-16
 */
@Service
public class LuntaiEquipmentServiceImpl implements ILuntaiEquipmentService {
    @Autowired
    private LuntaiEquipmentMapper luntaiEquipmentMapper;

    @Autowired
    private LuntaiEquipmentUseLogMapper luntaiEquipmentUseLogMapper;

    /**
     * 查询轮胎器材
     *
     * @param id 轮胎器材主键
     * @return 轮胎器材
     */
    @Override
    public LuntaiEquipment selectLuntaiEquipmentById(Integer id) {

        return luntaiEquipmentMapper.selectLuntaiEquipmentById(id);
    }

    /**
     * 查询轮胎器材列表
     *
     * @param luntaiEquipment 轮胎器材
     * @return 轮胎器材
     */
    @Override
    public List<LuntaiEquipment> selectLuntaiEquipmentList(LuntaiEquipment luntaiEquipment) {
        return luntaiEquipmentMapper.selectLuntaiEquipmentList(luntaiEquipment);
    }

    /**
     * 新增轮胎器材
     *
     * @param luntaiEquipment 轮胎器材
     * @return 结果
     */
    @Override
    public int insertLuntaiEquipment(LuntaiEquipment luntaiEquipment) {
        int i = luntaiEquipmentMapper.insertLuntaiEquipment(luntaiEquipment);
        LuntaiEquipmentUseLog luntaiEquipmentUseLog = new LuntaiEquipmentUseLog();
        luntaiEquipmentUseLog.setEquipmentId(luntaiEquipment.getId());
        luntaiEquipmentUseLog.setUserId(Math.toIntExact(SecurityUtils.getUserId()));
        luntaiEquipmentUseLog.setNum(luntaiEquipment.getNum());
        luntaiEquipmentUseLog.setType(1);
        luntaiEquipmentUseLog.setCreateTime(new Date());
        luntaiEquipmentUseLogMapper.insertLuntaiEquipmentUseLog(luntaiEquipmentUseLog);
        return i;
    }

    /**
     * 修改轮胎器材
     *
     * @param luntaiEquipment 轮胎器材
     * @return 结果
     */
    @Override
    public int updateLuntaiEquipment(LuntaiEquipment luntaiEquipment) {
        return luntaiEquipmentMapper.updateLuntaiEquipment(luntaiEquipment);
    }

    /**
     * 批量删除轮胎器材
     *
     * @param ids 需要删除的轮胎器材主键
     * @return 结果
     */
    @Override
    public int deleteLuntaiEquipmentByIds(Integer[] ids) {
        return luntaiEquipmentMapper.deleteLuntaiEquipmentByIds(ids);
    }

    /**
     * 删除轮胎器材信息
     *
     * @param id 轮胎器材主键
     * @return 结果
     */
    @Override
    public int deleteLuntaiEquipmentById(Integer id) {
        return luntaiEquipmentMapper.deleteLuntaiEquipmentById(id);
    }
}
